//
//  WSBaseRequestViewController.m
//  WSBaseKit
//
//  Created by zhangcong on 2020/8/14.
//  Copyright © 2020 zhangcong. All rights reserved.
//

#import "WSBaseRequestViewController.h"
//#import "UIViewController+WSCategory.h"
#import <UIViewController+WSCategory.h>
@interface WSBaseRequestViewController ()

@end

@implementation WSBaseRequestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initRequestBlock];
    
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (![self valueForKey:@"tableView"]) {
            [self didRequest];
        }
    });
}

- (id)valueForUndefinedKey:(NSString *)key {
    return nil;
}

- (void)initRequestBlock {
    __weak id SELF = self;
    _errorBlock = ^(NSError *error) {
        [SELF didRequestError:error];
    };
    _completeBlock = ^(id data) {
        [SELF didRequestComplete:data];
    };
}

- (void)didRequestComplete:(id)data {
    [self hiddenProgress];
}

- (void)didRequestError:(NSError *)error {
    [self showError:error];
}

- (void)didRequest {
    [self showLoader:@"加载中..."];
}

@end
